<template>
	<div>
		<el-select class="w-ipt" v-model="type" placeholder="请选择类型" @change="handleCheckType" size="medium">
			<el-option v-for="item in type_list" :key="item.id" :label="item.type_name" :value="item.type_value">
			</el-option>
		</el-select>
	</div>
</template>

<script>
	import API from '@/api/index.js'

	export default {
		data() {
			return {
				type_list: [],
				type: this.parent_type
			}
		},
		props: ['parent_type'],
		watch: {
			parent_type(val) {
				this.type = val;
			}
		},
		mounted() {
			this.getDeviceType();
		},
		methods: {
			getDeviceType() {
				let self = this;
				API.deviceType().then(res => {
					let data = res.data.data;
					self.type_list = data;
				}).catch(err => {
					self.$message.error(err.response.data.message)
				});
			},
			// 选择了Type
			handleCheckType(val) {
				let self = this;
				self.$emit('getType', {
					type: val
				})
			}
		}
	}
</script>

<style scoped lang="scss">
</style>
